package health.carousel.parsers;

import health.carousel.data.PositionDetails;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.mail.MessagingException;
import java.io.IOException;

public class MsnPositionDetailsParser extends PositionDetailsParser {
    private static final Logger log = LoggerFactory.getLogger(MsnPositionDetailsParser.class);


    public PositionDetails parsePositionDetails(String line, String seeking) throws MessagingException,
            IOException {
        //lines to parse
        /*
        OR RN, 8 Hour Variable, 13wks, $75
        ·         OR RN, 8 Hour Nights, 13wks, $75
        ·         Tele (strong candidate, Stepdown quality), 12 Hour Days, 6wks, $62.47
        ·         Tele, 12 Hour Days, 8wks, $62.47
        ·         Tele, 12 Hour Nights, 8wks, $62.47
        ·         Med Surg General, 12 Hour Nights, 13wks, $62.47
        ·         Med Surg Rehab, 8 Hour Days, 13wks, $62.47
        ·         ICU, 12 Hour Nights, 13wks, $75
        ·         ICU, 12 Hour Nights, 13wks, $75
        ·         ER, 12 Hour Days, 13wks, $75
        ·         PEDS/Adult MS, 12 Hour Nights, 13wks, $75  - primarily PEDS will float to Adult MS
        ·         Cath Lab RN, 8 Hour Days, 13wks, $75
        ·         PACU for Surgery Center, 8 Hour Days (24 hours per week), 4-6wks, $65.15
        ·         PACU for Surgery Center, 8 Hour Days (24 hours per week), 4-6wks, $65.15

        */
        //

        String[] splitDetails = line.trim().split(", ");

        String facility = splitDetails[0];
        String shiftTime = splitDetails[1];
        String termsLength = splitDetails[2];
        String[] priceAndAdditionalDetails = splitDetails[3].trim().split(" ");
        String price =  priceAndAdditionalDetails[0];
        String additionalDetails = "";

        for (int priceAndAdditionalDetailsElementPosition = 1; priceAndAdditionalDetailsElementPosition < priceAndAdditionalDetails.length; priceAndAdditionalDetailsElementPosition++) {
            if(!additionalDetails.equals("")){
                additionalDetails += " ";
            }
            additionalDetails += priceAndAdditionalDetails[priceAndAdditionalDetailsElementPosition];
        }

        for (int splitDetailsElementPosition = 4; splitDetailsElementPosition < splitDetails.length;
             splitDetailsElementPosition++) {
            additionalDetails += ", " + splitDetails[splitDetailsElementPosition];
        }


        String requestor = seeking
                .replaceAll(", is seeking:", "")
                .replaceAll(", is seeking", "")
                .replaceAll(" is seeking", "")
                .replaceAll(", is.*?seeking:", "")
                .replaceAll(",is.*?seeking", "")
                .replaceAll("is.*?seeking:", "")
                .replaceAll("is.*?seeking", "");

        return new PositionDetails(
                1,
                shiftTime,
                termsLength,
                price,
                facility,
                null,
                null,
                requestor,
                additionalDetails,
                line);
    }

}
